"use strict";
cc._RF.push(module, '22b81PAok1C76ierfwXBnAC', 'HallDailyView');
// scripts/HallDailyView.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var r = t("GlobalUserData"),
    s = t("Hint"),
    l = t("BroadCastMessage"),
    c = t("Util"),
    d = t("Global"),
    h = t("RedPointControl "),
    p = t("GoldFlyAnim"),
    u = t("BoxGetView"),
    f = t("HallConstant"),
    m = t("DailyItem"),
    _ = cc._decorator,
    y = _.ccclass,
    g = _.property,
    v = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.pfb_dialyItem = null, e.pfb_box = null, e.pfb_fly = null, e.content_Scroll = null, e.lab_videoNum = null, e.btn_get = null, e.btn_video = null, e.btn_nextDay = null, e.btnShowAd = null, e.videoIcon = null, e.TTVideoIcon = null, e._hallControl = null, e.nVideoTotal = 0, e.Reward_Data = [{
      get: !1,
      video: 0,
      gold: 1500,
      diamond: 30,
      other: {
        type: "vit",
        num: 10
      }
    }, {
      get: !1,
      video: 1,
      gold: 2500,
      diamond: 50,
      other: {
        type: "vit",
        num: 20
      }
    }, {
      get: !1,
      video: 3,
      gold: 3500,
      diamond: 100,
      other: {
        type: "vit",
        num: 30
      }
    }, {
      get: !1,
      video: 5,
      gold: 7500,
      diamond: 150,
      other: {
        type: "vit",
        num: 50
      }
    }, {
      get: !1,
      video: 10,
      gold: 1e4,
      diamond: 200,
      other: {
        type: "vit",
        num: 60
      }
    }, {
      get: !1,
      video: 15,
      gold: 15e3,
      diamond: 300,
      other: {
        type: "vit",
        num: 80
      }
    }, {
      get: !1,
      video: 20,
      gold: 2e4,
      diamond: 500,
      other: {
        type: "vit",
        num: 100
      }
    }], e.arrRewardState = [], e.mistakeBannerTimer = null, e.nPrevDate = 0, e.arrDailyItem = [], e.btnGetClickOnce = !1, e.canShowMistakeBanner = !0, e;
  }

  return n(e, t), e.prototype.onLoad = function () {
    c.Util.is_tt() && (this.videoIcon.active = !1, this.TTVideoIcon.active = !0), this.initVideoData(), this.initRewardData(), this.updateView();
  }, e.prototype.start = function () {
    var t = this;
    c.Util.hideHallBanner(), this.btnShowAd.active = !1, c.Util.wxReportUseBehavior("HallDailyView", "getState", 1), !r["default"].bAuditMode && this.canShowMistakeBanner && r["default"].isShowMistakeBanner ? this.mistakeBannerTimer = setTimeout(function () {
      c.Util.showMistakeBanner(function () {
        t.mistakeBannerTimer = setTimeout(function () {
          c.Util.hideMistakeBanner(), c.Util.showBanner();
        }, 2e3);
      }, function () {
        c.Util.showBanner();
      });
    }, 1e3) : c.Util.showBanner(), c.Util.hideSingleCustomAd(!1), c.Util.hideSingleCustomAd(!0);
  }, e.prototype.onEnable = function () {}, e.prototype.onDisable = function () {
    c.Util.hide_VerticalCustomAd(!1), c.Util.hide_VerticalCustomAd(!0);
  }, e.prototype.initView = function (t) {
    this._hallControl = t;
  }, e.prototype.initRewardData = function () {
    this.arrRewardState.length = 0;
    var t = c.Util.getCurDayDate(),
        e = cc.sys.localStorage.getItem("user_dailyreward_data");

    if (e) {
      var o = JSON.parse(e);

      if (this.nPrevDate = o.date, t > this.nPrevDate) {
        this.nPrevDate = t;

        for (var i = 0; i < this.Reward_Data.length; i++) {
          this.arrRewardState.push(!1);
        }
      } else for (i = 0; i < o.reward.length; i++) {
        this.arrRewardState.push(o.reward[i]);
      }
    } else for (this.nPrevDate = t, i = 0; i < this.Reward_Data.length; i++) {
      this.arrRewardState.push(!1);
    }
  }, e.prototype.saveRewardData = function (t, e) {
    this.arrRewardState[t] = e;
    var o = c.Util.getCurDayDate();

    if (o > this.nPrevDate) {
      for (var i = 0; i < this.arrRewardState.length; i++) {
        this.arrRewardState[i] = !1;
      }

      this.nPrevDate = o;
    }

    var n = JSON.stringify({
      reward: this.arrRewardState,
      date: this.nPrevDate
    });
    cc.sys.localStorage.setItem("user_dailyreward_data", n);
  }, e.prototype.initVideoData = function () {
    this.nVideoTotal = c.Util.getDailyVidoNum();
  }, e.prototype.updateView = function () {
    this.lab_videoNum.string = this.nVideoTotal.toString(), this.content_Scroll.width = 0 + 270 * this.Reward_Data.length;

    for (var t = 0; t < this.Reward_Data.length; t++) {
      this.arrDailyItem[t] || (this.arrDailyItem[t] = this.createItem(this.content_Scroll, cc.v3(0 + 270 * t, 0, 0))), this.arrDailyItem[t].updateItem(t, this.Reward_Data[t], this.arrRewardState[t], this.Reward_Data.length, this.nVideoTotal);
    }

    this.showBtnView();
  }, e.prototype.createItem = function (t, e) {
    var o = cc.instantiate(this.pfb_dialyItem);
    return o.position = e, t.addChild(o), o.getComponent(m["default"]);
  }, e.prototype.showBtnView = function () {
    this.btn_get.node.active = !1, this.btn_video.node.active = !1, this.btn_nextDay.node.active = !1;

    for (var t = !1, e = 0; e < this.arrRewardState.length; e++) {
      if (!this.arrRewardState[e]) {
        if (this.nVideoTotal >= this.Reward_Data[e].video) return this.btn_get.node.active = !0, r["default"].saveDailyRedPointState(2), void h.RedPointControl.getInstance().cal(d.RedPointCalKey.Daily);
        t = !0;
      }
    }

    t ? (this.btn_video.node.active = !0, c.Util.videoExposure(d.VideoTab.dim9), this.canShowMistakeBanner = !1, r["default"].saveDailyRedPointState(1), h.RedPointControl.getInstance().cal(d.RedPointCalKey.Daily)) : (this.canShowMistakeBanner = !0, this.btn_nextDay.node.active = !0, r["default"].saveDailyRedPointState(1), h.RedPointControl.getInstance().cal(d.RedPointCalKey.Daily));
  }, e.prototype.onClickNativeBanner = function () {
    c.Util.clickNativeBanner(1);
  }, e.prototype.onBtnClose = function () {
    clearTimeout(this.mistakeBannerTimer), this.playAudio(f.Audio_ID.btn_click), this.node.destroy(), c.Util.hideBanner(), c.Util.hideMistakeBanner(), c.Util.showSingleCustomAd(), c.Util.showHallBanner(), c.Util.hideNativeBanner();
  }, e.prototype.onBtnGet = function () {
    if (0 != this.btnGetClickOnce || 0 != r["default"].bAuditMode || 1 != this.canShowMistakeBanner || 1 != r["default"].isShowMistakeBanner) {
      this.btnGetClickOnce = !1, this.playAudio(f.Audio_ID.btn_click);

      for (var t = 0; t < this.Reward_Data.length; t++) {
        if (!this.arrRewardState[t] && this.nVideoTotal >= this.Reward_Data[t].video) return void this.onGetSuccess(t);
      }
    } else this.btnGetClickOnce = !0;
  }, e.prototype.onBtnVideo = function () {
    var t = this;
    this.playAudio(f.Audio_ID.btn_click), c.Util.showRewardVideo(function () {
      t.initVideoData(), t.updateView();
    });
  }, e.prototype.onGetSuccess = function (t) {
    clearTimeout(this.mistakeBannerTimer), c.Util.wxReportUseBehavior("HallDailyView", "getState", 2), c.Util.hideMistakeBanner(), s["default"].show("领取成功！"), this.saveRewardData(t, !0), this.updateView();
    var e = this.Reward_Data[t];

    switch (this.onGetGold(e.gold, t), this.onGetDiamond(e.diamond, t), e.other.type) {
      case "vit":
        this.onGetVit(e.other.num, t);
        break;

      case "box_common":
        this.onGetBox(u.Box_Type.common);
        break;

      case "box_middle":
        this.onGetBox(u.Box_Type.middle);
        break;

      case "box_senior":
        this.onGetBox(u.Box_Type.senior);
    }
  }, e.prototype.onGetGold = function (t, e) {
    r["default"].saveGoldData(!0, t), this._hallControl.onSetOwnGold(!0), this.playAudio(f.Audio_ID.get_gold);

    var o = this._hallControl.getGoldWorldPos(),
        i = new cc.Node();

    this.node.addChild(i), i.position = this.node.convertToNodeSpaceAR(this.arrDailyItem[e].getGoldWorldPos()), c.Util.AnimFly(p.Fly_Type.Gold, this.pfb_fly, i, o, function () {}, function () {
      i.destroy();
    });
  }, e.prototype.onGetDiamond = function (t, e) {
    r["default"].saveDiamondData(!0, t), this._hallControl.onSetOwnDiamond(!0), this.playAudio(f.Audio_ID.get_gold);

    var o = this._hallControl.getDiamondWorldPos(),
        i = new cc.Node();

    this.node.addChild(i), i.position = this.node.convertToNodeSpaceAR(this.arrDailyItem[e].getDiamondWorldPos()), c.Util.AnimFly(p.Fly_Type.Diammond, this.pfb_fly, i, o, function () {}, function () {
      i.destroy();
    });
  }, e.prototype.onGetVit = function (t, e) {
    r["default"].saveVitData(!0, t), this._hallControl.onSetOwnVit(!0), this.playAudio(f.Audio_ID.get_gold);

    var o = this._hallControl.getVitWorldPos(),
        i = new cc.Node();

    this.node.addChild(i), i.position = this.node.convertToNodeSpaceAR(this.arrDailyItem[e].getVitWorldPos()), c.Util.AnimFly(p.Fly_Type.vit, this.pfb_fly, i, o, function () {}, function () {
      i.destroy();
    });
  }, e.prototype.onGetBox = function (t) {
    var e = this;
    this.scheduleOnce(function () {
      var o = cc.instantiate(e.pfb_box);
      e.node.addChild(o), o.getComponent(u["default"]).showOpenBoxView(t, e._hallControl);
    }, 1);
  }, e.prototype.playAudio = function (t) {
    this._hallControl ? this._hallControl.playAudio(t) : l["default"].getInstance().SendMessage(f.Broadcast_Func.Audio, t);
  }, a([g(cc.Prefab)], e.prototype, "pfb_dialyItem", void 0), a([g(cc.Prefab)], e.prototype, "pfb_box", void 0), a([g(cc.Prefab)], e.prototype, "pfb_fly", void 0), a([g(cc.Node)], e.prototype, "content_Scroll", void 0), a([g(cc.Label)], e.prototype, "lab_videoNum", void 0), a([g(cc.Button)], e.prototype, "btn_get", void 0), a([g(cc.Button)], e.prototype, "btn_video", void 0), a([g(cc.Button)], e.prototype, "btn_nextDay", void 0), a([g(cc.Node)], e.prototype, "btnShowAd", void 0), a([g(cc.Node)], e.prototype, "videoIcon", void 0), a([g(cc.Node)], e.prototype, "TTVideoIcon", void 0), a([y], e);
}(cc.Component);

o["default"] = v;

cc._RF.pop();